package com.bjpowernode.crm.workbench.web.controller;

import com.bjpowernode.crm.commons.resp.Result;
import com.bjpowernode.crm.commons.utils.ChartVo;
import com.bjpowernode.crm.workbench.service.TranService;
import jdk.nashorn.internal.ir.LiteralNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.ws.handler.Handler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName:charController
 * Package:com.bjpowernode.crm.workbench.web.controller
 * Date:2022/6/18 16:01
 * Description:
 * Author:zsm@zhangshuming.com
 */
@Controller
public class CharController {
    @Autowired
    private TranService tranService;
    @RequestMapping("/workbench/chart/transaction/index.do")
    public String index(){

        return "workbench/chart/transaction/index";
    }

    @RequestMapping("/workbench/chart/transaction/queryCountOfTranGroupByStage.do")
    @ResponseBody
    public Result queryCountOfTranGroupByStage(){
        Result result = Result.FRR();
        try {
            // 获得每个阶段交易的数量
            List<ChartVo> chartVoList =tranService.queryCountOfTranGroupByStage();
            List<String> nameList = new ArrayList<>();
            List<String> valueList = new ArrayList<>();
            for (ChartVo c:chartVoList){
                nameList.add(c.getName());
                valueList.add(c.getValue());
            }

            Map<String,Object> param = new HashMap<>();
            param.put("nameList", nameList);
            param.put("valueList", valueList);
            param.put("chartVoList",chartVoList);
            result = Result.SUCCESS();
            result.setBody(param);
        } catch (Exception e) {
            e.printStackTrace();
            return result;
        }
        return result;
    }

}
